package com.zking.ssm.DYM.controller;

import com.zking.ssm.DYM.model.HotelRoomNum;
import com.zking.ssm.DYM.service.IHotelRoomNumService;
import com.zking.ssm.util.JsonData;
import com.zking.ssm.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author XXXXX
 * @Date 2021/01/20 10:48
 */
@Controller
@RequestMapping("/hotelRoomNum")
public class HotelRoomNumController {
    @Autowired
    private IHotelRoomNumService hotelRoomNumService;

    @ModelAttribute
    public void init(Model model){
        System.out.println("正在初始化。。。。。");
        HotelRoomNum hotelRoomNum = new HotelRoomNum();
        model.addAttribute("hotelRoomNum",hotelRoomNum);
    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public JsonData list(HotelRoomNum hotelRoomNum, PageBean pageBean){
        System.out.println("list");
        List<HotelRoomNum> hotelRoomNumList = hotelRoomNumService.list(hotelRoomNum, pageBean);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("查询成功");
        jsonData.setResult(hotelRoomNumList);
        return jsonData;
    }

    @RequestMapping("/updateHotelRoomNum/{id}")
    public String updateHotelRoomNum(@PathVariable("id")Long id,Model model){
        model.addAttribute("hotelRoomNum",hotelRoomNumService.selectByPrimaryKey(id));
        return "updateHotelRoomNum";
    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public String update(HotelRoomNum hotelRoomNum){
        hotelRoomNumService.updateByPrimaryKey(hotelRoomNum);
        return "redirect:updateHotelRoomNum";

    }
}
